/*
 * TextEditor.java - Copyright Apr 18, 2012 Z Networks Group, Inc. All rights reserved.
 * Z Networks Group PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.andromeda.skadi.view.swing;

import com.andromeda.skadi.property.EditableProperty;
import com.andromeda.skadi.view.swing.listener.SkadiFocusListener;
import java.awt.BorderLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author Dickinson Roman Arismendy Torres
 */
public class SwingTextEditor extends JPanel implements SwingEditor<String> {

    private JTextField textField;
    private EditableProperty<Boolean> focussed = new EditableProperty<Boolean>();

    public SwingTextEditor() {
        textField = new JTextField();
        textField.addFocusListener(new SkadiFocusListener("onFocusChanged", this));
        add(textField, BorderLayout.CENTER);
    }

    private void onFocusChanged() {
        focussed.set(textField.isFocusOwner());
    }

    @Override
    public EditableProperty<Boolean> focussed() {
        return focussed;
    }

    @Override
    public Class<String> renderedClass() {
        return String.class;
    }

    @Override
    public JComponent getEditorComponent() {
        return this;
    }
}
